package gui;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JScrollPane;
import javax.swing.border.LineBorder;
import javax.swing.tree.TreePath;

import domein.DomeinController;

public class ReisplanOverzichtPanel extends javax.swing.JPanel {
	private DomeinController domeinController;
	private ReisplanFrame reisplanFrame;
	private TreePath[] locaties;
	private Map<String, JCheckBox> checkboxes;
	private JButton btnRouteBerekenen;
	private ReisplanLocatiesOverzichtPanel pnlLocaties;
	private JScrollPane jScrollPane1;
	private List<String> routes;

	public ReisplanOverzichtPanel(DomeinController domeinController, ReisplanFrame reisplanFrame, TreePath[] locaties) {
		super();
		this.domeinController = domeinController;
		this.reisplanFrame = reisplanFrame;
		this.locaties = locaties;
		this.checkboxes = new HashMap<String, JCheckBox>();
		this.routes = new ArrayList<String>();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setPreferredSize(new Dimension(600, 390));
			this.setLayout(null);
			{
				jScrollPane1 = new JScrollPane();
				this.add(jScrollPane1);
				jScrollPane1.setBounds(12, 12, 576, 200);
				jScrollPane1.setBorder(new LineBorder(new java.awt.Color(78, 101, 125), 1, false));
				{
					pnlLocaties = new ReisplanLocatiesOverzichtPanel(locaties);
					jScrollPane1.setViewportView(pnlLocaties);
					pnlLocaties.setBounds(12, 12, 576, 200);
				}
			}
			{
				checkboxes.put("chkKortste", new JCheckBox());
				this.add(checkboxes.get("chkKortste"));
				checkboxes.get("chkKortste").setText("Kortste Route");
				checkboxes.get("chkKortste").setBounds(20, 235, 140, 24);
				checkboxes.get("chkKortste").setForeground(new java.awt.Color(255,255,255));
			}
			{
				checkboxes.put("chkLangste", new JCheckBox());
				this.add(checkboxes.get("chkLangste"));
				checkboxes.get("chkLangste").setText("Langste Route");
				checkboxes.get("chkLangste").setBounds(20, 270, 140, 24);
				checkboxes.get("chkLangste").setForeground(new java.awt.Color(255,255,255));
			}
			{
				checkboxes.put("chkDroogste", new JCheckBox());
				this.add(checkboxes.get("chkDroogste"));
				checkboxes.get("chkDroogste").setText("Droogste Route");
				checkboxes.get("chkDroogste").setBounds(223, 235, 140, 24);
				checkboxes.get("chkDroogste").setForeground(new java.awt.Color(255,255,255));
			}
			{
				checkboxes.put("chkNatste", new JCheckBox());
				this.add(checkboxes.get("chkNatste"));
				checkboxes.get("chkNatste").setText("Natste Route");
				checkboxes.get("chkNatste").setBounds(223, 270, 140, 24);
				checkboxes.get("chkNatste").setForeground(new java.awt.Color(255,255,255));
			}
			{
				checkboxes.put("chkKoudste", new JCheckBox());
				this.add(checkboxes.get("chkKoudste"));
				checkboxes.get("chkKoudste").setText("Koudste Route");
				checkboxes.get("chkKoudste").setBounds(422, 235, 140, 24);
				checkboxes.get("chkKoudste").setForeground(new java.awt.Color(255,255,255));
			}
			{
				checkboxes.put("chkWarmste", new JCheckBox());
				this.add(checkboxes.get("chkWarmste"));
				checkboxes.get("chkWarmste").setText("Warmste Route");
				checkboxes.get("chkWarmste").setBounds(422, 270, 140, 24);
				checkboxes.get("chkWarmste").setForeground(new java.awt.Color(255,255,255));
			}
			{
				btnRouteBerekenen = new JButton();
				this.add(btnRouteBerekenen);
				btnRouteBerekenen.setText("Route(s) Berekenen");
				btnRouteBerekenen.setBounds(203, 306, 180, 28);
				btnRouteBerekenen.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {			
						for(Map.Entry<String, JCheckBox> entry : checkboxes.entrySet()) {
							JCheckBox box = entry.getValue();
							
							if(box.isSelected())
								routes.add(box.getText());
						}
						
						reisplanFrame.showResult(routes, locaties);
					}
				});
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
